const Promise = require('bluebird');
const Apply = require('../models/apply');

module.exports = function(body) {
    const processor = function(t) {
        return Promise.try(() => {
            return body.items;
        })
        .map(item => {
            item.creator = body.creator;
            item.start_time = new Date();
            return Apply.safeForge(item)
            .save({}, {
                transacting: t
            });
        });
    };
    return Apply.buildTransaction(processor);
};
